<template>
  <div class="main">
    
      <div class="content">
        <el-row :gutter="10">
          <el-col :span="16">
                <div class="news-detail">
                    <h1 class="news-title">{{newsdetail.name}}</h1>
                    <p class="news-info">
                      <span>所属类别：{{newsdetail.categoryName}}</span>
                      <span>发布时间：{{newsdetail.createtime}}</span>
                      <span>阅读量：{{newsdetail.readNum}}</span>
                    </p>
                    <div class="contenthtml" style="width:100%;" v-html="newsdetail.content">
                    </div>

                     <contactus3></contactus3>
                </div>
                <div class="xiangguang">
                    <div class="title">
                      <h1>相关文章</h1>
                    </div>
                    <ul>
                      <li v-for="(item,index) in newlist" :key="index">
                        <nuxt-link :to="'/post/' + item.pid"><span class="newsname">{{item.name}}</span></nuxt-link>
                        <span>{{item.createtime.slice(0,11)}}</span>
                      </li>
                    </ul>
                </div>

          </el-col>
          <el-col :span="8">
                <contactus></contactus>
                <div class="newsBox">
                    <h1><a href="">| 热销产品</a></h1>
                    <div>
                        <div class="productDetali"  v-for="(item,index) in productlist" :key="index">
                          <nuxt-link :to="'/product/'+ item.pid"><h2>{{item.name.slice(0,17)}}</h2></nuxt-link>
                           <p><span>{{item.productCategory}}</span> <span>预期年化收益率：</span><i>{{item.yearEarningsRate}}%</i></p>
                        </div>
                    </div>
                </div>
                <detailnews :newslist="newlist"></detailnews>
           </el-col>
        </el-row>
      </div>
  </div>
</template>

<script>
import api from '../../../../static/js/api.js'
import asyncApi from '../../../../static/js/asyncApi.js'
import contactus from "../../../../components/contactus";
import detailnews from "../../../../components/detailnews";
import contactus3 from "../../../../components/contactus3";


export default {
  // data(){
  //   return{
  //     newsdetail:{},
  //     productlist:{}
  //   }
  // },
  components: {
    contactus,
    detailnews,
    contactus3
  },
  methods:{
    goproduct(val){
        this.$router.push("/product/" + val)
    },
    getPostDetail(id){
      api.getPostDetail({id:id}).then((res)=>{
        this.newsdetail = res.data
      })
    },
    getproduct(){
      api.getProduct({page:"1",pageSize:"5"}).then((res)=>{
        this.productlist = res.data.list
      })
    }

  },
  mounted :function(){
    // this.getPostDetail(this.$route.params.id);
    // this.getproduct();
  },
  async asyncData (context) {
    var id = parseInt(context.params.id);
    let [data1,data2,data3] = await Promise.all([
        asyncApi.asyncGetCategoryPost({page: "1",pageSize: "4"}),
        asyncApi.asyncgetPostDetail({id:id}),
        asyncApi.asyncgetProduct({page:"1",pageSize:"5"})
    ])
    return {
      newlist:data1.data.data.list,
      newsdetail:data2.data.data,
      productlist:data3.data.data.list
    }
 },
};
</script>

<style scoped>
.xiangguang{
  background: white;
  padding: 20px;
}
.xiangguang .title{
  border-bottom: 1px solid #cd9c54;
}
.newsname{
  display: inline-block;
  width: 600px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.main .xiangguang h1{
  font-size: 16px;
  width: 150px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: white;
  background: #cd9c54;
}
.xiangguang ul{
  padding:  0 30px;
}
.xiangguang ul li{
  display: flex;
  justify-content: space-between;
  height: 50px;
  line-height: 50px;
  font-size: 14px;
  color: #333;
}
.productDetali{
  height: 100px;
  border-bottom:1px solid #ccc; 
}
.productDetali p{
  color: #666;
}
.productDetali i{
  color: #b41d24;
}
.productDetali p span:nth-child(2){
  margin-left: 30px;
}
.productDetali h2{
  height: 50px;
  line-height: 50px;
  font-size: 18px;
  color: #333;
  font-weight: bolder;
  margin-top: 20px;
}
.news-detail{
  padding: 20px;
  background: white;
}
.news-title{
  text-align: center;
}
.news-info{
  display: flex;
  border-bottom: 1px solid #ccc;
  justify-content: space-between;
  padding: 10px 50px;
}
.contenthtml p{
  color: red !important;
}

.newsBox{
  background: white;
  padding: 20px;
  margin-top: 10px;
}
.newsBox h1 {
  color: #cd9c54 !important;
  font-size: 20px !important;
  height: 30px;
  line-height: 30px;
  border-bottom:1px solid #ccc; 
}

.main {
  width: 1200px;
  margin: 10px auto;
}
.main h1 {
  font-size: 20px;
  line-height: 30px;
  color: black;
  font-weight: normal;
}


</style>
